<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/23/023
 * Time: 12:33
 */

namespace app\portal\controller;


use cmf\controller\HomeBaseController;
use think\Db;

class ClubController extends HomeBaseController
{
    /**
     * 俱乐部页面
    */
    public function index()
    {
        //获取俱乐部数据
        return $this->fetch(':club');
    }

    /**
     * 俱乐部加盟
     */
    public function league()
    {
        return $this->fetch(':league');
    }

    /**
     * 俱乐部数据
     */
    public function clubData()
    {
        $keywords = input('get.keywords');
        $id = input('get.id');
        if ( empty($id)) {
            $this->assign('id',0);
        } else {
            $address = Db::name('club')->where('id','=',$id)->find();
            $this->assign('address',$address);
            $this->assign('id',$id);
        }
        if( empty($keywords)) {
            $where = '1=1';
        }
        else
        {
            $where['club_name|club_address'] = ['like',"%$keywords%"];
            $this->assign('keywords',$keywords);
        }
        $clubList = Db::name('club')->where($where)->paginate(5,false,[
            'query' => request()->param(),
        ]);
        $total= ceil($clubList->total() /5);
        $currentPage = $clubList->currentPage();
        $pre_id = ($currentPage==1)?1:$currentPage-1;
        $next_id = ($currentPage==$total)?$currentPage:$currentPage+1;
        $this->assign('clubList',$clubList);
        $this->assign('pre_id',$pre_id);
        $this->assign('next_id',$next_id);
        $this->assign('total',$total);
        $this->assign('page',$currentPage);
        $this->assign('url',$this->request->url());
        return $this->fetch(':map');
    }
}